#include <iostream>

using namespace std;

template <typename T>
void selectSort(T pt[], int TCount, T(compare)(T a, T b))
{
    cout << "数组大小" << sizeof(pt) / sizeof(T) << endl;
    for (int i = 0; i < TCount; i++)
    {
        T temp;
        for (int j = i + 1; j < TCount; j++)
        {
            temp = compare(pt[i], pt[j]);
            if (temp != pt[i])
            {
                pt[j] = pt[i];
                pt[i] = temp;
            }
        }
    }
}

template <typename T>
void printArr(T pt[], int len)
{
    cout << "数组:";
    for (int i = 0; i < len; i++)
    {
        cout << pt[i] << " ";
    }
    cout << endl;
}

int MaxInt(int a, int b)
{
    return a > b ? a : b;
}

int MinInt(int a, int b)
{
    return a > b ? b : a;
}

char MaxChar(char a, char b)
{
    return a > b ? a : b;
}

char MinChar(char a, char b)
{
    return a > b ? b : a; 
}

int main()
{
    int a[10] = {1, 9, 2, 8, 3, 7, 4, 6, 100};
    cout << "数组大小" << sizeof(a) << "/" << sizeof(int) << endl;
    printArr<int>(a, 10);

    selectSort<int>(a, 10, MaxInt);
    printArr<int>(a, 10);

    char charArr[] = "defgabc";
    printArr<char>(charArr, sizeof(charArr) / sizeof(char));
    selectSort<char>(charArr, sizeof(charArr) / sizeof(char), MinChar);
    printArr<char>(charArr, sizeof(charArr) / sizeof(char));
}